package com.example.sort.controller;

import com.example.sort.entity.FreeNode;
import com.example.sort.result.ExceptionCodeEnum;
import com.example.sort.result.Result;
import com.example.sort.service.ISortService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@AllArgsConstructor
@RequestMapping("/test")
@Api(value = "测试接口", tags = {"测试使用"})
public class TestController {
    @Autowired
    private ISortService sortService;

    @GetMapping("/hello")
    @ApiOperation("hello")
    public String sayHello(){
        return "hello word";
    }

    @PostMapping("/asc")
    @ApiOperation("点位排序，去重")
    public Result asc(@RequestBody List<FreeNode> list){
        return Result.success(sortService.asc(list));
    }

    @GetMapping("/error")
    @ApiOperation("报错信息")
    public Result all(@RequestParam ExceptionCodeEnum enu){
        if(enu.equals(ExceptionCodeEnum.ERROR)){
            throw new RuntimeException("xxxxxxxxxxxxxxxxx");
        }
        return Result.success("ccc");
    }
}
